package com.hzjh.base.http

import com.google.gson.Gson
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody

/**
 * 接口请求添加通用请求参数
 */
fun Map<Any, Any>.toVersionParams(): RequestBody {
    val params = this.toMutableMap()
    return Gson().toJson(params)
        .toRequestBody("Content-Type, application/json".toMediaTypeOrNull())
}

fun toEmptyVersionParams(): RequestBody {
    val params = HashMap<Any, Any>()
    return Gson().toJson(params)
        .toRequestBody("Content-Type, application/json".toMediaTypeOrNull())
}

fun String.toParams(): RequestBody {
    return this.toRequestBody("Content-Type, application/json".toMediaTypeOrNull())
}

fun String.stringToRequestBody(): RequestBody {
    return this.toRequestBody("Content-Type,text/plain".toMediaTypeOrNull())
}